<template>
  <div class="no-print">
    <a-card class="info" title="任务委托">
      <template slot="extra">
        <!--<template v-if="model.bpmStatus==='1'">
        <a-button
                class="ruleButton"
                :ghost="true"
                type="primary"
                icon="edit"
                @click="handleEdit(model)"
                :disabled="isDisabledAuth('erpOmcTaskDistribution:edit')"
        />
        <a-divider type="vertical"/>
        <a-button type="primary" size="small" @click="startProcess(model)" :disabled="isDisabledAuth('erpOmcTaskDistribution:startProcess')">发起流程</a-button>
      </template>
      <template v-if="showBtn(model.bpmStatus)&& doCount > 0">
        <span v-if="model.taskUrge">
          <a-icon title="催办提醒" theme="twoTone" twoToneColor="#eb2f96"
                  @click="taskNotifyMe(flowCode,model.id)" type="notification"/>
          <a-divider type="vertical"/>
        </span>

        <a-button type="primary" size="small" @click="handleProcess(model)">办理</a-button>
        <a-divider type="vertical"/>
      </template>
      <template v-if="myCount > 0 && showBtn(model.bpmStatus)">
        <a-button type="primary" size="small" @click="taskNotify(flowCode,model.id)">催办</a-button>
        <a-divider type="vertical"/>
        <a-popconfirm title="确定要作废吗?" @confirm="() => invalidProcess(model)">
          <a-button type="primary" size="small" :disabled="isDisabledAuth('erpOmcTaskDistribution:invalidProcess')">
            作废流程
          </a-button>
        </a-popconfirm>
        <a-divider type="vertical"/>
      </template> -->
        <template v-if="model.bpmStatus !== '1'">
          <a-button
            type="primary"
            size="small"
            @click="handleTrack(model)"
            :disabled="isDisabledAuth('erpOmcTaskDistribution:viewTrack')">审批进度</a-button>
        </template>
      </template>
      <!--<biz-his-task-module ref="bizHisTask" :formData="formData">-->

      <a-row type="flex" justify="center">
        <a-col :span="24">
          <ErpProgressTaskChangeListForm v-if="model.applyType == '2'" ref="realForm" :disabled="true" normal>
          </ErpProgressTaskChangeListForm>
          <erp-omc-task-distribution-form v-else ref="realForm" :disabled="true" normal></erp-omc-task-distribution-form>
        </a-col>
      </a-row>
      <a-row type="flex" justify="center">
        <a-col :span="24">
          <!-- 流程历史跟踪 -->
          <common-flow-list v-if="model.bpmStatus !== '1'" :formData="formData"></common-flow-list>
        </a-col>
      </a-row>
      <!-- </biz-his-task-module>-->
      <erp-omc-task-distribution-modal ref="modalForm" @ok="modalFormOk"></erp-omc-task-distribution-modal>
      <bpm-biz-task-deal-modal
        ref="taskDealModal"
        :path="path"
        :formData="formData"
        @ok="handleOk"></bpm-biz-task-deal-modal>
      <bpm-process-track-modal ref="bpmProcessTrackModal"></bpm-process-track-modal>
      <biz-task-notify-modal ref="taskNotifyModal"></biz-task-notify-modal>
      <biz-task-notify-me-modal ref="taskNotifyMeModal"></biz-task-notify-me-modal>
    </a-card>
    <div style="text-align: center;margin-top: 15px;">
      <a-button @click="onPrint" type="primary">打印</a-button>
    </div>
    <ErpOmcTaskChangeFormPrint
      v-if="model.applyType === '2'"
      v-show="isPrint"
      id="printContent"
      class="print_style"
      :formData="model"
      :formDataHistory="formData"></ErpOmcTaskChangeFormPrint>
    <ErpOmcTaskDistributionFormPrint
      v-else
      id="printContent"
      v-show="isPrint"
      class="print_style"
      :formData="model"
      :formDataHistory="formData"></ErpOmcTaskDistributionFormPrint>
  </div>
</template>

<script>

import { getAction } from '@/api/manage'
import { JeecgBpmListMixin } from '@/mixins/JeecgBpmListMixin'
import ErpOmcTaskDistributionForm from './modules/ErpOmcTaskDistributionForm'
import ErpOmcTaskDistributionModal from './modules/ErpOmcTaskDistributionModal'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import CommonFlowList from '@/views/components/CommonFlowList.vue' // 审批历史流程列表组件
import ErpOmcTaskDistributionFormPrint from './modules/ErpOmcTaskDistributionFormPrint' // 打印组件
import Print from '@/utils/print/printarea.js';
import BizHisTaskModule from '@/views/modules/bpmbiz/common/BizHisTaskModule.vue';
import BpmBizTaskDealModal from '@/views/modules/bpmbiz/common/BpmBizTaskDealModal.vue';
import BpmProcessTrackModal from '@/views/modules/bpmbiz/common/BpmProcessTrackModal.vue';
import BizTaskNotifyModal from '@/views/modules/bpmbiz/common/BizTaskNotifyModal.vue';
import BizTaskNotifyMeModal from '@/views/modules/bpmbiz/common/BizTaskNotifyMeModal.vue';
import ErpProgressTaskChangeListForm from './modules/taskchange/ErpProgressTaskChangeListForm.vue'
import ErpOmcTaskChangeFormPrint from './modules/taskchange/ErpOmcTaskChangeFormPrint.vue'
export default {
  name: 'ErpOmcTaskDistributionDetail',
  mixins: [JeecgBpmListMixin, DisabledAuthFilterMixin],
  components: {
    ErpOmcTaskDistributionForm,
    ErpOmcTaskDistributionModal,
    BizHisTaskModule,
    BpmBizTaskDealModal,
    BpmProcessTrackModal,
    BizTaskNotifyModal,
    BizTaskNotifyMeModal,
    CommonFlowList,
    ErpOmcTaskDistributionFormPrint,
    ErpProgressTaskChangeListForm,
    ErpOmcTaskChangeFormPrint

  },
  data() {
    return {
      model: {},
      isPrint: false,
      id: '',
      url: {
        queryById: '/api/erp/omc/task/erpOmcTaskDistribution/queryById',
        delete: '/api/erp/omc/task/erpOmcTaskDistribution/delete',
        bizCount: '/api/erp/omc/task/erpOmcTaskDistribution/bizCount',
        submit: '/api/erp/omc/task/erpOmcTaskDistribution/submit',
        revoke: '/api/erp/omc/task/erpOmcTaskDistribution/revoke',
        counterTrial: '/api/erp/omc/task/erpOmcTaskDistribution/counterTrial',
        audit: '/api/erp/omc/task/erpOmcTaskDistribution/audit',
        overrule: '/api/erp/omc/task/erpOmcTaskDistribution/overrule'
      },
      confirmLoading: false,
      iconStyle: { 'font-size': '20px' },
      // 代码生成后需手动设置流程编码
      flowCode: 'dev_erp_omc_task_distribution_001',
      formUrl: '/omc/task/modules/ErpOmcTaskDistributionForm',
      formUrlMobile: ''
    }
  },
  created() {
  },
  watch: {
    $route(to, from) {
      this.loadData();
    }
  },
  mounted() {
  },
  methods: {
    loadData() {
      const id = this.$route.params.id;
      getAction(this.url.queryById, { id }).then((res) => {
        if (res.success) {
          const model = res.result
          this.model = model;
          this.$nextTick(() => {
            this.$refs.realForm.edit(model);
          })

          if (Number(res.result.applyType) === 2) {
            this.flowCode = 'dev_erp_omc_task_distribution_002'
          }
          // getAction('/api/erp/omc/task/erpOmcTaskDistributionDt/list', { mainId: id })
          //   .then(response => {
          //     // this.model.distributionDtList = response.result || []
          //     this.$set(this.model, 'distributionDtList', response.result || [])
          //   })

          this.getMembers(model.id)
          // this.getTemplates(model.id)
          this.getTaskNumber(model.taskId)

          // 查询流程
          let params = { flowCode: this.flowCode, dataId: this.model.id };// 查询条件
          this.viewTrack(params);
          // 查询催办
          let params1 = { flowCode: this.flowCode, dataId: id };// 查询条件
          getAction(this.url.checkNotify, params1).then((res2) => {
            if (res2.result) {
              this.model.taskUrge = true;
            }
          })
        }
      })
      this.bizCountById(id);
    },
    // 项目成员
    getMembers(mainId) {
      getAction('/api/erp/omc/task/erpOmcTaskDistributionDt/list', { mainId })
        .then(response => {
          this.model.distributionDtList = response.result || []
          this.$set(this.formData, 'distributionDtList', response.result || [])
        })
    },

    // 获取项目数据
    getTaskNumber(taskId) {
      // // 获取任务编号
      if (taskId) {
        getAction('/api/erp/omc/project/erpOmcProjectTaskFinal/queryPageList', { id: taskId }).then((res) => {
          if (res.success) {
            if (res.result.records && res.result.records.length) {
              var event = res.result.records[0]
              this.$set(this.formData, 'taskNo', event.billNo) // 任务编号
            }
          }
        })
      }
    },
    // 点击打印
    onPrint() {
      this.isPrint = true
      var _this = this
      this.$nextTick(() => {
        let print = new Print({
          el: '#printContent',
          popTitle: '任务委托详情 · 禾美环保',
          endCallback() {
            _this.isPrint = false
          }
        })
      })
    }
  }
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';

.info {
  /deep/ .ant-card-head-title {
    flex: none;
    margin-right: 20px;
  }

  /deep/ .ant-card-extra {
    flex: 1;
    float: left;
  }
}
</style>
